(function () {
    console.log("横截面文件");
    let now_open_diag = {}
    now_open_diag.API_URL = ''
    document.getElementById("todayTimer").innerHTML = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
    const devicePixelRatio = window.devicePixelRatio;//设备分辨率

    function Request(baseUrl = '', time = 1000) {
        this.baseUrl = baseUrl;
        function request(url, option = {}) {
            return new Promise(async (resolve, reject) => {
                try {
                    const response = await fetch(baseUrl + url, option);
                    if (response.status == '200') {
                        const data = await response.json();
                        if (data.code == '200') {
                            resolve(data);
                        } else {
                            reject(data.message || '请求失败');
                        }
                    } else {
                        reject(response);
                    }
                } catch (e) {
                    reject(e);
                }
            })
        }

        this.post = function (url, data) {
            return request(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
        }

        this.get = function (url) {
            return request(url, {
                method: 'GET'
            })
        }
    }


    Request.createRequest = function (baseUrl) {
        return new Request(baseUrl);
    }
    const request = Request.createRequest(now_open_diag.API_URL);

    let level = "A"
    const initRight = (obj) => {
        //console.log("重置温度场分布", document.getElementsByClassName("hjm_zhjl")[0].children[4])
        // let blArr = obj.tempFieldResult
        let blArr = obj.tempFieldArrayResult
        obj.runState == 1 || level == "SOFA" ? document.getElementsByClassName("hjm_zhjl")[0].children[4].className = "c nofire" : document.getElementsByClassName("hjm_zhjl")[0].children[4].className = "c"
        let oPointerWd = document.getElementsByClassName('hjm_wd_block')//着火距离点位
        // console.log(blArr[0][8].toFixed());
        let nowWenDU = blArr[0][8].toFixed() //现在取的温度值
        let c_1 = document.getElementsByClassName('c_1')[0]
        let c_2 = document.getElementsByClassName('c_2')[0].children

        nowWenDU > 1800 ? nowWenDU = 1800 : nowWenDU < 1500 ? nowWenDU = 1500 : ""
        c_1.style.opacity = nowWenDU == 0 ? 0 : ((1800 - nowWenDU) / 300).toFixed(2)//改变温度颜色 1500 对应 1    1800对应 0
        for (let index = 0; index < c_2.length; index++) {
            const element = c_2[index];
            element.style.scale = 1 + (nowWenDU / 10000).toFixed(2) * 1 //改变火焰大小  1000对应 1  2000对应1.2
        }

        blArr.forEach((item, i) => {
            item.forEach((otem, oi) => {
                oPointerWd[i].children[oi].innerHTML = otem.toFixed()
                let nowValue = otem.toFixed()
                let position = nowValue > upWd ? 255 : nowValue < loweWd ? 0 : ((nowValue - loweWd) * 255 / (upWd - loweWd)).toFixed()
                let color = colorPicker(position)
                // console.log(position, ((wdArr[i] * (otem * 10000)) / 10000).toFixed());
                // let color1=colorPicker(position)
                // console.log(`rgb(${color[0]},${color[1]},${color[2]})`);
                oPointerWd[i].children[oi].style.background = `rgb(${color[0]},${color[1]},${color[2]})`
            });

        });


    }
    // 绘制颜色映射图
    const defaultColorStops = { 0: "#0019ff", 0.1: "#00d8ff", 0.2: "#00dc50", 0.25: "#ffee00", 0.9: "#ff1800", 1: "#ff0000" };
    const width = 20, height = 256;
    const loweWd = 400, upWd = 1500
    // linear-gradient(to bottom, #ff1800, #ffee00, #00dc50, #00d8ff, #0019ff)
    // / 创建canvas
    let canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;
    // document.getElementById('_c').appendChild(canvas)
    let ctx = canvas.getContext("2d");
    // 创建线性渐变色
    let linearGradient = ctx.createLinearGradient(0, 0, width, height);
    for (const key in defaultColorStops) {
        linearGradient.addColorStop(key, defaultColorStops[key]);
    }
    // 绘制渐变色条
    ctx.fillStyle = linearGradient;
    ctx.fillRect(0, 0, width, height);
    // 读取像素数据
    let imageData = ctx.getImageData(0, 0, 1, height).data;
    const colorPicker = (position) => {
        return imageData.slice(position * 4, position * 4 + 3);
    }
    let whichFloor = 0
    let casd = []
    let runState = ""
    const setWhichFlood = (oi) => {
        // lsLoader("加载中...")
        whichFloor = oi
        // let arr = ["A", "B", "C", "D", "E", "燃尽风"]//,"燃尽风1","燃尽风2"
        let arr = ["A", "B", "C", "D", "燃尽风"]//,"燃尽风1","燃尽风2"
        let oTitle = document.getElementsByClassName('title')//标题
        let oA2A3 = document.getElementsByClassName('_t')//A2A3
        let oA1A4 = document.getElementsByClassName('_d')//A1A4
        // console.log(oA2A3, oA1A4);
        for (let i = 0; i < oA2A3.length; i++) {
            oA2A3[i].children[0].innerHTML = arr[oi] + 2;
            oA2A3[i].children[2].innerHTML = arr[oi] + 3;
        }
        for (let i = 0; i < oA1A4.length; i++) {
            oA1A4[i].children[0].innerHTML = arr[oi] + 1;
            oA1A4[i].children[2].innerHTML = arr[oi] + 4;
        }

        for (let i = 0; i < oTitle.length; i++) {
            let str = i == 0 ? "层燃烧器着火距离监测" : i == 1 ? "层燃烧器截面温度场偏烧情况" : "层燃烧器截面温度场分布"
            oTitle[i].children[0].innerHTML = arr[oi] + str;
        }
        if (oi == 4) {
            document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "0"
        } else {
            document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "1"
        }
        setZhDis()
    }
    let getdatashishi = null
    let getzhunshu = []
    const getData = () => {
        // 初始化表单数据
        clearInterval(getdatashishi)
        let ccc = [{ level: "A" }, { level: "B" }, { level: "C" }, { level: "D" }, { level: "SOFA" }]
        let arr = ["A", "B", "C", "D", "燃尽风"]
        request.post('/spf/visit/getThermalField', ccc[whichFloor]).then(res => {
            res.data && res.data.tempFieldArrayResult && res.data.tempFieldArrayResult.length > 0 && initRight(res.data)
            let arrbox = []
            for (let key in res.data.distince) {
                arrbox.push({
                    label: res.data.distince[key], // label 字段
                    value: key   // value字段
                })
            }

            if (arr[whichFloor] == "燃尽风") {
                document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "0"
            } else {
                if (res.data.runState == 1) {
                    document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "0"
                } else {
                    document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "1"
                }
            }
            console.log(res.data);
            casd = arrbox
            getzhunshu = res.data
            runState = res.data.runState
            setZhDis()
            removeLoader()
            getdatashishi = setInterval(() => { getData() }, 3000)
        })
    }

    const getDatas = () => {
        // 变换化表单数据
        let ccc = [{ level: "A" }, { level: "B" }, { level: "C" }, { level: "D" }, { level: "SOFA" }]
        let arr = ["A", "B", "C", "D", "燃尽风"]
        request.post('/spf/visit/getThermalField', ccc[whichFloor]).then(res => {
            console.log(res);
            if (arr[whichFloor] == "燃尽风") {
                document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "0"
            } else {
                if (res.data.runState == 1) {
                    document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "0"
                } else {
                    document.querySelector(".hjm_zhjl .c .c_2").style.opacity = "1"
                }
            }
            setZhDis()
        })
    }
    const setZhDis = () => {//重置着火距离
        let c_3 = document.querySelector('.c_3').children
        // let arr = ["A", "B", "C", "D", "E", "燃尽风"]//,"燃尽风1","燃尽风2"
        let arr = ["A", "B", "C", "D", "SOFA"]//,"燃尽风1","燃尽风2"
        let oPointerDis = document.getElementsByClassName('pointer_name')//着火距离点位
        //着火距离132
        casd.sort(function (a, b) {
            let valueA = a.value.toUpperCase(); // 不区分大小写进行排序
            let valueB = b.value.toUpperCase(); // 不区分大小写进行排序
            if (valueA < valueB) {
                return -1;
            }
            if (valueA > valueB) {
                return 1;
            }
            return 0;
        });
        // if (getzhunshu.zs !== undefined) {
        //     if (getzhunshu.zs[0] === 0) { c_3[1].style.display = "none" } else { c_3[1].style.display = "block" }
        //     if (getzhunshu.zs[1] === 0) { c_3[0].style.display = "none" } else { c_3[0].style.display = "block" }
        //     if (getzhunshu.zs[2] === 0) { c_3[3].style.display = "none" } else { c_3[3].style.display = "block" }
        //     if (getzhunshu.zs[3] === 0) { c_3[2].style.display = "none" } else { c_3[2].style.display = "block" }
        // } else {
        //     for (let index = 0; index < c_3.length; index++) {
        //         c_3[index].style.display = "none"
        //     }
        // }
        if (runState == 0) {
            oPointerDis[0].innerHTML = arr[whichFloor] + 1 + (arr[whichFloor] == "SOFA" ? "" : ": " + Number(casd[0].label.toFixed()) + "mm");
            oPointerDis[1].innerHTML = arr[whichFloor] + 2 + (arr[whichFloor] == "SOFA" ? "" : ": " + Number(casd[1].label.toFixed()) + "mm");
            oPointerDis[2].innerHTML = arr[whichFloor] + 3 + (arr[whichFloor] == "SOFA" ? "" : ": " + Number(casd[2].label.toFixed()) + "mm");
            oPointerDis[3].innerHTML = arr[whichFloor] + 4 + (arr[whichFloor] == "SOFA" ? "" : ": " + Number(casd[3].label.toFixed()) + "mm");
            let c_2 = document.getElementsByClassName('c_2')[0].children

            if (Number(casd[0].label.toFixed() >= 400)) {
                c_2[1].style.scale = 1.6
                c_3[1].style.display = "block"
            } else if (Number(casd[0].label.toFixed() == 0)) {
                c_2[1].style.scale = 0
                c_3[1].style.display = "none"
            } else {
                c_2[1].style.scale = 1
                c_3[1].style.display = "block"
            }
            if (Number(casd[1].label.toFixed() >= 400)) {
                c_2[0].style.scale = 1.6
                c_3[0].style.display = "block"
            } else if (Number(casd[1].label.toFixed() == 0)) {
                c_2[0].style.scale = 0
                c_3[0].style.display = "none"
            } else {
                c_2[0].style.scale = 1
                c_3[0].style.display = "block"
            }
            if (Number(casd[2].label.toFixed() >= 400)) {
                c_2[2].style.scale = 1.6
                c_3[3].style.display = 'block'
            } else if (Number(casd[2].label.toFixed() == 0)) {
                c_2[2].style.scale = 0
                c_3[3].style.display = 'none'
            } else {
                c_2[2].style.scale = 1
                c_3[3].style.display = 'block'
            }
            if (Number(casd[3].label.toFixed() >= 400)) {
                c_2[3].style.scale = 1.6
                c_3[2].style.display = 'block'
            } else if (Number(casd[3].label.toFixed() == 0)) {
                c_2[3].style.scale = 0
                c_3[2].style.display = 'none'
            } else {
                c_2[3].style.scale = 1
                c_3[2].style.display = 'block'
            } //改变火焰大小  1000对应 1  2000对应1.2
        } else {
            oPointerDis[0].innerHTML = arr[whichFloor] + 1
            oPointerDis[1].innerHTML = arr[whichFloor] + 2
            oPointerDis[2].innerHTML = arr[whichFloor] + 3
            oPointerDis[3].innerHTML = arr[whichFloor] + 4
        }


        // removeLoader()

    }
    const initEvent = (str) => {//
        //获取事件元素
        let oFootBtns = document.getElementById(str).children //底部菜单 btns
        if (str == "zbf_foot_btns") {
            now_open_diag.username == "admin" ? "" : oFootBtns[oFootBtns.length - 1].style.display = "none"
            // now_open_diag.username == "admin" ? "" : oFootBtns[oFootBtns.length - 2].style.display = "none"
        }
        for (let i = 0; i < oFootBtns.length; i++) {
            oFootBtns[i].onclick = () => {
                for (let ii = 0; ii < oFootBtns.length; ii++) {
                    oFootBtns[ii].className = ""
                }
                oFootBtns[i].className = "active"
                if (str == "zbf_hjm_btns") {
                    lsLoader('加载中....')
                    setWhichFlood(i)
                    getDatas()
                } else {
                    function closeDiag() {
                        timer ? clearInterval(timer) : ""
                        oTodayTimer ? clearInterval(oTodayTimer) : ""
                        // var tab_titlenodes = document.getElementsByClassName('ls_tabtitle')[0].getElementsByTagName('li');
                        // onCloseTab(tab_titlenodes[now_open_diag.index].childNodes[1].childNodes[0])
                    }
                    switch (i) {
                        case 0:
                            closeDiag()
                            setTimeout(() => {
                                window.location.href = "/index.html"
                            }, 200)
                            break;
                        case 1:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("全炉膛温度场", 11, "SJDL_IFS_DATA.prj", "全炉膛温度场")
                                window.location.href = "/quanlutang.html"
                            }, 200)

                            break;
                        case 2:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("横截面", 6, "SJDL_IFS_DATA.prj", "横截面")
                                window.location.href = "/hjm.html"
                            }, 200)

                            break;
                        case 3:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("燃烧稳定性监测", 7, "SJDL_IFS_DATA.prj", "燃烧稳定性监测")
                                window.location.href = "/ranshaowendingxing.html"
                            }, 200)

                            break;
                        case 4:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("煤粉分配率", 9, "SJDL_IFS_DATA.prj", "煤粉分配率")
                                window.location.href = "/meifen.html"
                            }, 200)

                            break;
                        case 5:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("煤粉颗粒度分布", 8, "SJDL_IFS_DATA.prj", "煤粉颗粒度分布")
                                window.location.href = "/main/dcimgs/gl/main.html"
                            }, 200)

                            break;
                        case 6:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("预警信息", 12, "SJDL_IFS_DATA.prj", "预警信息")
                                window.location.href = "/yujing.html"
                            }, 200)

                            break;
                        case 7:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("历史数据", 10, "SJDL_IFS_DATA.prj", "历史数据")
                                window.location.href = "/history.html"
                            }, 200)

                            break;
                        case 8:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("预警阈值配置修改", 14, "SJDL_IFS_DATA.prj", "预警阈值配置修改")
                                window.location.href = "/canshushezhi.html"
                            }, 200)

                            break;
                        default:

                    }

                }
            }
        }
    }
    initEvent('zbf_foot_btns') //底部菜单 btns
    initEvent('zbf_hjm_btns') //底部菜单 btns
    // let c_form = eval('formview_' + now_open_diag.fmname)
    // c_form.onready = function () {// 页面打开 数据加载完成
    //     initDataFromINnput()
    // }
    lsLoader('加载中....')
    let timer = setTimeout(() => {
        getData()
    }, 500)
    let oTodayTimer = setInterval(() => {
        document.getElementById("todayTimer").innerHTML = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
    }, 1000)


})()
